package com.young.common.core.base;

import com.young.common.client.ums.UmsClientHelper;
import com.young.common.model.BaseDO;
import com.young.common.model.enums.ETrashFlagEnum;
import com.young.interfaces.ums.model.User;

import java.util.Date;

/**
 * controller基类
 *
 * @author wangjy
 * @date 2021/10/28 23:42:06
 */
public abstract class BaseController {

    /**
     * 插入填充
     * @param baseDO
     */
    public void fillForInsert(BaseDO baseDO) {
        User user = UmsClientHelper.getLoginUser();
        baseDO.setCreateUserId(user.getId());
        baseDO.setCreateUserName(user.getName());
        baseDO.setUpdateUserId(user.getId());
        baseDO.setUpdateUserName(user.getName());
        baseDO.setCreateTime(new Date());
        baseDO.setUpdateTime(new Date());
        if (baseDO.getDataSequence() == null) {
            baseDO.setDataSequence(1L);
        }
        baseDO.setDataVersion(1L);
        if (baseDO.getTrashFlag() == null) {
            baseDO.setTrashFlag(ETrashFlagEnum.VALID.type);
        }
    }

    /**
     * 更新填充
     * @param baseDO
     */
    public void fillForUpdate(BaseDO baseDO) {
        User user = UmsClientHelper.getLoginUser();
        baseDO.setUpdateUserId(user.getId());
        baseDO.setUpdateUserName(user.getName());
        baseDO.setUpdateTime(new Date());
    }
}
